package com.google.code.netbuilder.dal.providersimpl;

import com.google.code.netbuilder.dal.entities.Cable;
import java.sql.SQLException;
import java.util.List;

import com.google.code.netbuilder.dal.entities.CableWire;
import com.google.code.netbuilder.dal.providers.ICableWireProvider;
import com.google.code.netbuilder.dal.services.JPAServise;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;

public class CabelWireProviderJPA implements ICableWireProvider {
    
        private static EntityManager em = JPAServise.getEntityManager();
        private static EntityTransaction trans = em.getTransaction();

	@Override
	public void save(CableWire entity) {
                trans.begin();
                em.persist(entity);
                trans.commit();
	}

	@Override
	public void update(CableWire entity) {
                trans.begin();
                em.merge(entity);             
                trans.commit();
	}

	@Override
	public void delete(CableWire entity) {
                trans.begin();
                em.remove(entity);             
                trans.commit();
	}

	@Override
	public List findAll() {
                Query query = em.createQuery("SELECT c FROM CableWire c");
                return (List<CableWire>) query.getResultList();
	}

	@Override
	public CableWire findByID(Integer id) {
		return em.find(CableWire.class, id);
	}

}
